package net.yunxinyong.cec.controller;

import net.yunxinyong.cec.entity.Cec711FourNonprofitOrganization;
import net.yunxinyong.cec.service.Cec711FourNonprofitService;
import net.yunxinyong.cec.utils.CECResult;
import net.yunxinyong.cec.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author 李跃
 * @date 18/9/18
 */
@RequestMapping(value = "711four")
@Controller
public class Cec711FourController {
    @Autowired
    private Cec711FourNonprofitService cec711FourNonprofitService;

    @PostMapping("add")
    public CECResult insertFour(@RequestBody Cec711FourNonprofitOrganization cec711FourNonprofitOrganization){
        int i = cec711FourNonprofitService.insertFour(cec711FourNonprofitOrganization);
        //这里由于业务原因没有对是否存在企业进行判断,所以这里的i只简单处理一下
        if(i ==100 ){
            return  CECResult.build(500,"企业信息已存在");
        }
        return CECResult.build(200,"企业信息添加为空");
    }

    @GetMapping(value = "delete")
    public CECResult delete(@RequestParam(value = "id") Integer id){
        int i = cec711FourNonprofitService.deleteFour(id);
        if(i > 0){
            return   CECResult.build(200,"企业信息删除成功");
        }
        return CECResult.build(500,"企业信息删除失败");
    }

    @PostMapping(value = "update")
    public CECResult update(@RequestBody Cec711FourNonprofitOrganization cec711FourNonprofitOrganization){
        int i = cec711FourNonprofitService.update(cec711FourNonprofitOrganization);
        if(i > 0){
            return CECResult.build(200,"企业信息修改失败");
        }
        return CECResult.build(500,"企业信息修改失败");
    }

    @PostMapping(value = "get/{page}/{rows}")
    public CECResult getInfo(@RequestBody Cec711FourNonprofitOrganization cec711FourNonprofitOrganization, @PathVariable int page, @PathVariable int rows){
        PageBean pageBean = cec711FourNonprofitService.ListFourByName(page, rows,cec711FourNonprofitOrganization );
        if(!pageBean.getPageDatas().isEmpty()){
            return CECResult.build(500,"没有查询到企业信息",pageBean);
        }
        return CECResult.build(200,"查询到了企业信息",pageBean);
    }

}

